package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.mapper.SkuInfoMapper;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2024/9/8 0:59
 */
@RestController
@RequestMapping("/admin/product")
public class SkuController {
    @Autowired
    SkuInfoService skuInfoService;
    //sku分页
    @GetMapping("/list/{page}/{limit}")
    public Result skuPage(@PathVariable Long page,@PathVariable Long limit){
        //设置参数
        Page<SkuInfo> skuInfoPage = new Page<>(page,limit);
        Page<SkuInfo> infoPage = skuInfoService.page(skuInfoPage);
        return Result.ok(infoPage);
    }
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){

        skuInfoService.saveSkuInfo(skuInfo);
        return Result.ok();
    }
    //上架
    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){

        skuInfoService.upOrdown(skuId,1);
        return Result.ok();
    }
    //下架
    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){

        skuInfoService.upOrdown(skuId,0);
        return Result.ok();
    }
}
